package com.bsj.travel.auth.controller;

import com.bsj.travel.auth.form.LoginBody;
import com.bsj.travel.auth.service.SystemLoginService;
import com.bsj.travel.def.global.JsonResult;
import com.bsj.travel.security.service.TokenService;
import com.bsj.travel.def.common.VO.TokenUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * @author yinhao
 * @version 1.0
 * @description 用户登录Token控制
 * @date 2023/11/3
 */
@RestController
public class TokenController {

    @Autowired
    private TokenService tokenService;
    @Autowired
    private SystemLoginService systemLoginService;

    /**
     * 登录
     * @param body
     * @return
     */
    @PostMapping(value = "/login")
    public JsonResult<Map> login(@RequestBody LoginBody body) {
        //登录
        TokenUser tokenuser = systemLoginService.login(body.getUserName(), body.getPassWord());
        //获取登录令牌
        return JsonResult.success(tokenService.createToken(tokenuser));
    }
}
